<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="强化学习Reinforcement Learning, J Sir">
    <meta name="description" content="">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>强化学习Reinforcement Learning | J Sir</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery.min.js"></script>

<meta name="generator" content="Hexo 6.0.0">
<style>.github-emoji { position: relative; display: inline-block; width: 1.2em; min-height: 1.2em; overflow: hidden; vertical-align: top; color: transparent; }  .github-emoji > span { position: relative; z-index: 10; }  .github-emoji img, .github-emoji .fancybox { margin: 0 !important; padding: 0 !important; border: none !important; outline: none !important; text-decoration: none !important; user-select: none !important; cursor: auto !important; }  .github-emoji img { height: 1.2em !important; width: 1.2em !important; position: absolute !important; left: 50% !important; top: 50% !important; transform: translate(-50%, -50%) !important; user-select: none !important; cursor: auto !important; } .github-emoji-fallback { color: inherit; } .github-emoji-fallback img { opacity: 0 !important; }</style>
</head>




<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">J Sir</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友情链接</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">J Sir</div>
        <div class="logo-desc">
            
            Never really desperate, only the lost of the soul.
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/jy741" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/jy741" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/medias/featureimages/19.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">强化学习Reinforcement Learning</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        padding: 35px 0 15px 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        padding-bottom: 30px;
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/">
                                <span class="chip bg-color">机器学习</span>
                            </a>
                        
                            <a href="/tags/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/">
                                <span class="chip bg-color">深度学习</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2023-03-07
                </div>
                

                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    4.7k
                </div>
                

                

                
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="far fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
        </div>
        <hr class="clearfix">

        
        <!-- 是否加载使用自带的 prismjs. -->
        <link rel="stylesheet" href="/libs/prism/prism.css">
        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <h1 id="奶茶鼠的想法"><a href="#奶茶鼠的想法" class="headerlink" title="奶茶鼠的想法"></a>奶茶鼠的想法</h1><p>三月🥰</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/4d358ff7b558d139d7fe7b7cdeac2026955ec0a0.png@1036w.webp" alt="img" style="zoom:50%;"></p>
<span id="more"></span>
<h1 id="What-is-RL"><a href="#What-is-RL" class="headerlink" title="What is RL"></a>What is RL</h1><h2 id="Introduction"><a href="#Introduction" class="headerlink" title="Introduction"></a>Introduction</h2><p>强化学习的过程和机器学习是一样的，都是寻找函数。不过在强化学习中寻找的函数叫做actor，actor 跟Environment会进行互动，actor能够接受环境给予的observation（观察），并根据这个observation做出action去影响 Environment，然后Environment会给这个 Actor 一些 reward（奖励），这个reward说明action是好是坏，如此循环往复。我们的目的就是寻找一个用 Observation 当作Input，输出 Action，能将Reward总和最大化的actor。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307134515274.png" alt="image-20230307134515274" style="zoom:50%;"></p>
<h2 id="Example"><a href="#Example" class="headerlink" title="Example"></a>Example</h2><p>我们以Space invader这个游戏来可视化解释强化学习到底是啥。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307134640834.png" alt="image-20230307134640834"></p>
<p>在这个游戏里，游戏界面就是observation，人即决策者就是actor，向左向右跟开火就是action，游戏机就是Environment，得到的游戏分数就是reward。游戏的画面变的时候就代表了有了新的 Observation 进来，有了新的 Observation 进来，你的 Actor 就会决定採取新的 Action。我们想要 Learn 出一个 Actor，使用它在这个游戏裡面的时候，可以让我们得到的 Reward 的总和会是最大的。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307134816969.png" alt="image-20230307134816969"><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307134735650.png" alt=""></p>
<p>AlphaGo也是强化学习的一个例子，棋盘当作observation，AlphaGo相当于actor，而李世石相当于environment。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307135014945.png" alt="image-20230307135014945"><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307135029137.png" alt="image-20230307135029137"></p>
<h2 id="Step-Of-RL"><a href="#Step-Of-RL" class="headerlink" title="Step Of RL"></a>Step Of RL</h2><p>强化学习和机器学习一样也分为三步。</p>
<p>我们来回顾一下机器学习的三步：</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307135137489.png" alt="image-20230307135137489"></p>
<h3 id="Function-with-Unknown"><a href="#Function-with-Unknown" class="headerlink" title="Function with Unknown"></a>Function with Unknown</h3><p>将机器的观察用向量或矩阵来表示，作为actor的输入；actor输出的每个action对应输出层的每个神经元，每个action会有一个分数。这样看和分类任务是一个东西，不同的点是：强化学习将这些分数作为几率，按照这个几率随机产生输出，也就是sample（采样），而不是将分数最高的那个作为输出。</p>
<p>採取 Sample 有一个好处是说，就算是看到同样的游戏画面，机器每一次採取的行为也会略有不同，在很多的游戏裡面这种随机性也许是重要的，比如说你在做剪刀石头布的时候如果总是会出石头，就很容易被打爆，如果有一些随机性就比较不容易被打爆。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307135650697.png" alt="image-20230307135650697"></p>
<h3 id="Define-loss"><a href="#Define-loss" class="headerlink" title="Define loss"></a>Define loss</h3><p>这里定义loss也就是定义分数的获得机制，但是我们最后想要最大化的是整局的全部分数之和，而不是局部某一次的分数。负的 Total Reward当做 Loss</p>
<p>补充：一局游戏就是一个episode；reward是某一个行为能立即得到的奖励，return是所有分数相加（total reward）。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307135827236.png" alt="image-20230307135827236"><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307135843449.png" alt="image-20230307135843449"></p>
<h3 id="Optimization"><a href="#Optimization" class="headerlink" title="Optimization"></a>Optimization</h3><p>环境产生的Observation s1 进入actor，actor通过采样输出一个a1，a1再进入环境产生s2，如此往复循环，直到满足游戏中止的条件。s 跟 a 所形成的这个 Sequence又叫做 Trajectory，用 𝜏 来表示。</p>
<p>需要注意的是reward不是只看action，还需要看 Observation，所以 Reward 是一个 Function。</p>
<p>优化目标：找到 Actor 的一组参数，让R(𝜏)的值越大越好。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307140017928.png" alt="image-20230307140017928"></p>
<p>强化学习最主要的难点就是如何做optimizaton：</p>
<ul>
<li>action是通过采样产生的，具有很大的随机性，给相同的s，产生的a可能是不一样的。<ul>
<li>一般的Network在不同的random seed设定下的随机性，是”Training”中的随机性，比如初始化参数随机；但是在Testing中，同样的输入会获得同样的输出。 RL的随机性是在测试时，固定模型参数，同样的输入observation，会有不同的输出action。</li>
</ul>
</li>
<li>只有actor是网络，Environment 和 Reward,根本就不是 Network ，只是一个黑盒子而已；Environment与Reward都有随机性。<ul>
<li>环境是黑箱，採取一个行为环境会有对应的回应，但是不知道到底是怎麽产生这个回应，给定同样的行为，它可能每次的回应也都是不一样，具有随机性。</li>
<li>Reward就是一个奖励的规则，也不是 Network。</li>
</ul>
</li>
</ul>
<h1 id="Policy-Gradient"><a href="#Policy-Gradient" class="headerlink" title="Policy Gradient"></a>Policy Gradient</h1><h2 id="How-to-control-actor"><a href="#How-to-control-actor" class="headerlink" title="How to control actor"></a>How to control actor</h2><p>如果希望Actor在看到某个s时采取某一种行为，只需要把actor输出想成一个分类的问题，为每个Observation设定一个$\hat{a}$（即Ground Truth或label）。针对某一个Observation，$\hat{a}$是向左移动，如果希望actor采取该行为，则计算Actor跟 Ground Truth 之间的 Cross-entropy，学习让Cross-entropy最小的 θ，就可以让这个 Actor的输出跟Ground Truth 越接近越好；如果不希望actor采取该行为，则令$L=-e$，再学出能够使L最小的actor参数 。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307141441823.png" alt="image-20230307141441823"></p>
<p>当有很多Observation时，每一个Observation对应一个a，同时会有一个对应的e。假如我们希望在s时，actor做出$\hat{a}$的行为；而在s′时，不希望actor做出 $\hat{a}^′$的行为，那么此时的loss就变成了$L=e1-e2$，然后去找一个 θ 去 Minimize Loss，得到θ*</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307141704072.png" alt="image-20230307141704072"></p>
<p>延伸到N个Observation。收集一堆这种资料，定义一个 Loss Function，训练 Actor，Minimize 这个 Loss Function，期待Actor执行我们的行为</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307141736946.png" alt="image-20230307141736946"></p>
<p>使用权重和影响系数，控制每个行为的重要性，有多希望 Actor 去执行。这样train出来的actor才会更加符合我们的期望。</p>
<p>那么难点有两个（也就是下图画问号的）：</p>
<ol>
<li>如何产生成对的{s，$\hat{a}$}。</li>
<li>如何确定我们的A</li>
</ol>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307142004458.png" alt="image-20230307142004458"></p>
<h2 id="Definition-of-A"><a href="#Definition-of-A" class="headerlink" title="Definition of A"></a>Definition of A</h2><h3 id="Version-0"><a href="#Version-0" class="headerlink" title="Version 0"></a>Version 0</h3><script type="math/tex; mode=display">
A_n = r_n</script><p>让一个（随机的）Actor 去跟环境做互动，把它在每一个Observation执行的行为action都记录下来，每一个行为对应一个奖励Reward，将这个即时的Reward作为每个pair的A值。通常收集资料不会只把 Actor 跟环境做一个 Episode，通常会做多个 Episode，然后期待可以收集到足够的资料</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307142231897.png" alt="image-20230307142231897"></p>
<p>但是这是鼠目寸光的一个版本，没有长程规划的概念（同贪心算法）：</p>
<p>每个行为不是独立的，会影响互动接下来的发展。有些奖励是会有延迟的Reward Delay，需要牺牲短暂的奖励来获得长程的奖励。以太空游戏为例，左右移动是没有奖励的，只有开火会有奖励，采用版本0则会导致actor一直做开火动作，不会左右移动。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307142320450.png" alt="image-20230307142320450"></p>
<h3 id="Version-1"><a href="#Version-1" class="headerlink" title="Version 1"></a>Version 1</h3><script type="math/tex; mode=display">
G_t = \sum_{n=t}^Nr_n \\
A_n = G_n</script><p>$a_t$有多好，不仅取决于 $r_t$，也取决于 $a_t$ 之后所有发生的事情。为了考虑到延迟奖励，将每个行为的后续所有行为的奖励Reward也加入到该批次来得到数值 $G_t$。这些G称为cumulated reward（累积奖励）。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307142508071.png" alt="image-20230307142508071"></p>
<p>但这个版本也有一个问题，即某个行为对后续行为产生奖励的影响都是一样的，假设这个过程非常地长的话，因为做$a_1$导致可以得到$r_N$的可能性应该很低。实际上某个行为对后续行为的影响并不是一样的，该行为对越靠近它的后续行为影响越大，越往后影响越小。</p>
<h3 id="Version-2"><a href="#Version-2" class="headerlink" title="Version 2"></a>Version 2</h3><script type="math/tex; mode=display">
G_t^′ = \sum_{n=t}^N\gamma^{n-t}r_n \\
A_n = G_n^′</script><p>解决版本1的问题，引入折扣因子discount factor（&lt;1），这个折扣系数成幂次增长。这次计算出来的奖励称为discount cumulated reward（折扣累积奖励）。可以给离$a_1$比较近的那些 Reward比较大的权重，比较远的那些 Reward比较小的权重</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307142808574.png" alt="image-20230307142808574"></p>
<p>这也存在一定问题，就是没有考虑标准化，算出来的奖励是不具备参考性的，因为好的奖励分数和坏的奖励分数是相对的。同样是60分，全班很多人都考了90分，那60分就是差的，全班很多人都不及格，那60分就是好的。如果我们只是单纯的把 G 算出来，可能每一个行为都会给我们正的分数，只是有大有小的不同，有些行为其实是不好的，但是你仍然会鼓励Model去採取这些行为</p>
<h3 id="Version-3"><a href="#Version-3" class="headerlink" title="Version 3"></a>Version 3</h3><script type="math/tex; mode=display">
G_t^′ = \sum_{n=t}^N\gamma^{n-t}r_n \\
A_n = G_n^′-b</script><p>标准化奖励，把所有的 G’ 都减掉一个 b（这个 b通常叫做 Baseline），A就有正有负了（采用减去b的方法）， 这样就知道这个奖励在整体中到底是好是差，类似于算排名的感觉。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307143318135.png" alt="image-20230307143318135"></p>
<h2 id="Procedure-of-Policy-Gradient"><a href="#Procedure-of-Policy-Gradient" class="headerlink" title="Procedure of Policy Gradient"></a>Procedure of Policy Gradient</h2><p>Policy Gradient基本思想如下：</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307143505338.png" alt="image-20230307143505338"></p>
<p>其中要注意的是收集Data是在循环内的，也就是说每一次更新的$\theta$都是这个参数的actor和环境互动收集的数据来更新的，更新后需要重新和环境互动来拿到新的Data以便更新参数。</p>
<h2 id="On-policy-vs-Off-policy"><a href="#On-policy-vs-Off-policy" class="headerlink" title="On-policy vs Off-policy"></a>On-policy vs Off-policy</h2><p>On-policy——训练的actor和跟环境互动的actor是一个，也就是我们上述提到的每个迭代都需要重新跟环境互动收集Data来更新参数的</p>
<p>Off-policy——训练的actor和跟环境互动的actor不是同一个</p>
<p>Off-policy可以实现前一个参数$\theta ^{i-1}$的actor跟环境互动收集的Data可以用来训练$\theta$，这样我们可以不用每一次迭代都需要收集Data</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307145824762.png" alt="image-20230307145824762"></p>
<p>Off-policy有一个很著名的方法Proximal Policy Optimization (PPO)，主要思想就是训练的actor知道和跟环境互动的actor他们两者的差距。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307145929929.png" alt="image-20230307145929929"></p>
<h2 id="Exploration"><a href="#Exploration" class="headerlink" title="Exploration"></a>Exploration</h2><p>Actor採取行为的随机性是非常重要的，很多时候随机性不够会训练不起来或训练不出好的结果。如果没有随机性，可能一些 Action 从来没被执行过，那就根本无从知道这个 Action 好或不好。就是要尽力遍历各种可能性，这样才能更加全面地考虑和做决策。</p>
<p>为了让Actor做出的action尽可能全面，我们往往采用一些Exploration的方法，如Enlarge output entropy、Add noises onto parameters。这样可以有效防止如在太空入侵者这个游戏中，actor只会向左，他都不知道开火会获得什么奖励这种情况。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307150238217.png" alt="image-20230307150238217"></p>
<h1 id="Actor-Critic"><a href="#Actor-Critic" class="headerlink" title="Actor-Critic"></a>Actor-Critic</h1><h2 id="Introduction-1"><a href="#Introduction-1" class="headerlink" title="Introduction"></a>Introduction</h2><p>Critic是用来评价actor好坏的，可以用价值函数$V^θ (s)$来表示，当使用参数为θ的actor时，看到s后预估获得的折扣累积奖励。这个价值函数相当于未卜先知，看到s就知道actor会有什么样的表现。Critic考虑了参数θ下actor的所有可能的action，在面对某一s时，$V^θ (s)$是所有可能奖励discounted cumulated Reward的平均结果。所以价值函数是与评估的actor相关的，当有相同的observation时，不同的actor有不同的$V^θ (s)$。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307150621982.png" alt="image-20230307150621982"></p>
<h2 id="How-to-estimate-V-θ-s"><a href="#How-to-estimate-V-θ-s" class="headerlink" title="How to estimate $V^θ (s)$"></a>How to estimate $V^θ (s)$</h2><h3 id="Monte-Carlo-MC"><a href="#Monte-Carlo-MC" class="headerlink" title="Monte-Carlo (MC)"></a>Monte-Carlo (MC)</h3><p>让actor和环境互动，玩这个游戏以后得到一些记录，在输入sa后，游戏玩完之后就能得到discounted cumulated Reward的值为Ga′。利用这些训练资料，只需要让critic看到某个 s 后输出的值$V^θ (s)$与对应的G’越接近越好。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307150923565.png" alt="image-20230307150923565"></p>
<p>问题是，有的游戏其实很长，甚至有的游戏根本就没有不会结束，一直继续下去，那像这样子的游戏，MC 就非常地不适合</p>
<h3 id="Temporal-difference-TD"><a href="#Temporal-difference-TD" class="headerlink" title="Temporal-difference (TD)"></a>Temporal-difference (TD)</h3><p>不需要玩完游戏就可以开始训练了，只要在看到Observation $s<em>t$， Actor 執行了 $a_t$获得$r_t$，接下來再看到$s</em>{t+1} $就能夠訓練$V^θ (s)$了。</p>
<p>$V^θ (s<em>t)$和 $V^θ (s</em>{t+1})$存在数学等式关系：前者减去γ倍后者就等于rt，所以只要训练这个差值接近rt就好。蒐集到 rt 这一笔资料，输入st和st+1，带入前述公式，差值要跟 rt 越接近越好</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307151015096.png" alt="image-20230307151015096"></p>
<h3 id="MC-v-s-TD"><a href="#MC-v-s-TD" class="headerlink" title="MC v.s. TD"></a>MC v.s. TD</h3><p>同样的资料，同样的θ，用 MC 跟 TD 算出来的 Value Function很有可能会是不一样的。<br>下面代表玩了8次游戏，也就是8个episode。为了简化，无视actor和折扣。</p>
<ul>
<li>Actor 第一次玩游戏的时候，它先看到sa这个画面，得到 Reware 0，接下来看到sb这个画面,得到 Reware 0 游戏结束</li>
<li>接下来有连续六场游戏,都是看到sb这个画面，得到 Reward 1 就结束了</li>
<li>最后一场游戏看到sb这个画面,得到 Reward 0 就结束了</li>
</ul>
<p>8次游戏中看到8次sb，其中6次是的1分，2次是0分，所以sb的价值函数是3/4。</p>
<ul>
<li>MC：sa和sb是有关联的，看到了sa就会让sb的reward=0。只看到一次sa，discounted cumulated Reward值为0。故$V^θ (sa)$=0</li>
<li>TD：前后两个state是没有关系的，sa之后看到sb，但sb的reward不会受sa的影响，而sb期望的Reward=3/4，所以计算得到$V^θ (sa)$=3/4</li>
</ul>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307151417278.png" alt="image-20230307151417278"></p>
<h2 id="Version-3-5"><a href="#Version-3-5" class="headerlink" title="Version 3.5"></a>Version 3.5</h2><p>将价值函数用于训练actor<strong>。</strong>在version 3中就有提到标准化，是通过减去b来实现的，在这个版本中这个b用$V^θ (s)$来表示。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307151525448.png" alt="image-20230307151525448"></p>
<p>玩完一局游戏产生的资料是{st，at}，但我们是基于一个分布来采样行为，即看到st后actor能够做许多种行为，将所有这些可能行为的 Gt’ 都算出来并做平均，就得到了$V^θ (s)$，所以$V^θ (s)$代表平均实力。Gt’ 含义是在 st 这个画面下，执行 at 以后，再一路玩下去，会得到的实际 Cumulative Reward。$A_t = G_t^′ - V^θ (s)$就是把个人分数减去班级平均成绩，这样就能看出个人分数是否过了平均线，也就判断了这个行为是好是坏。假如算出的At大于0，则证明at行为比随便执行的actor要好，其分数是在平均线以上，是个好的行为。</p>
<p>但是这个版本中仍存在问题，就是at之后的所有行为都是采样出来的，我们考察的是at是不是个好行为，不能让后面的特殊情况影响到了对at的判断。Gt′是一次采样，可能存在特殊性。例如at是个差的行为，但是后面sample出来的行为碰巧大部分都有很高的奖励分数，这样就使得判断有失偏颇。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307151853078.png" alt="image-20230307151853078"></p>
<h2 id="Version-4"><a href="#Version-4" class="headerlink" title="Version 4"></a>Version 4</h2><p>对于采取at行为后的期望奖励，上个版本是直接用当前采样出的路径，而这个版本是用at产生的即时奖励rt，加上从st+1开始玩所有可能Gt+1′的均值（即$V^θ (s_{t+1})$），这样才能真正代表at产生的效益有多大。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307151937984.png" alt="image-20230307151937984"></p>
<h2 id="Tip-of-Actor-Critic"><a href="#Tip-of-Actor-Critic" class="headerlink" title="Tip of Actor-Critic"></a>Tip of Actor-Critic</h2><p>actor和critic的参数是可以共享的。actor是接受s，输出不同的行为并给出分数作为sample的几率；critic是接受s，输出一个数值，这个数字代表接下来的累积奖励。两者都要接受s，对s的处理肯定有相同的做法，所以两者可以共用前几层的layer网络，后面几层网络根据特性分别设计。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307152025177.png" alt="image-20230307152025177"></p>
<h1 id="Reward-Shaping"><a href="#Reward-Shaping" class="headerlink" title="Reward Shaping"></a>Reward Shaping</h1><h2 id="sparse-reward"><a href="#sparse-reward" class="headerlink" title="sparse reward"></a>sparse reward</h2><p>有些场景Reward大多数时候都是0，只有在少数时候是一个非常大的数值，这意味着很多action无从判断是好是坏，例如机器臂拧螺丝，初始化时它就在空中隨便揮舞怎麼揮舞 Reward 都是 0，除非它正好非常巧合的拿起一個螺絲，再把它拴進去，才得到正向的 Reward。这时就需要我们提供额外的reward来帮助机器学习（比如越靠近螺丝奖励越多，螺丝离孔越近奖励越多），自定义奖励的方法就叫reward shaping。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307152354879.png" alt="image-20230307152354879"></p>
<p>以vizdoom游戏为例，这个游戏只有最后胜负这一个奖励，所以需要参赛队给自己的机器设置自定义奖励机制。例如扣血了就减分，捡到血包就加分，站着不动扣分，活着也扣分（防止边缘OB）</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307152457720.png" alt="image-20230307152457720"></p>
<h2 id="Curiosity"><a href="#Curiosity" class="headerlink" title="Curiosity"></a>Curiosity</h2><p>就是给机器加上好奇心，让他喜欢探索新事物，特别地，不应看到“噪声”——无意义的“新”。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307152715384.png" alt="image-20230307152715384"></p>
<h1 id="No-reward-Learning-from-Demonstration"><a href="#No-reward-Learning-from-Demonstration" class="headerlink" title="No reward:Learning from Demonstration"></a>No reward:Learning from Demonstration</h1><h2 id="Imitation-Learning"><a href="#Imitation-Learning" class="headerlink" title="Imitation Learning"></a>Imitation Learning</h2><p>有了自定义奖励，我们为什么还要研究无奖励的情况呢？第一是因为在某些任务中不知道怎么去定义reward。第二是因为有些人为定义的奖励（reward-shaping)，如果你的 Reward 沒想好，Machine 可能會產生非常奇怪、無法預期的行為。比如，利用强化学习学习自动驾驶，如何给礼让行人、闯红灯定reward？</p>
<p>actor可以和环境互动但是却没有reward，这种情况就适合使用示范学习，就是先让人类去示范一下怎么跟環境互動，把人類跟環境的互動記錄下來记作τ^，然后用这些示范行为去训练机器。例如自动驾驶：记录人类的驾驶行为，机器臂：拉着机器臂做一次。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307152920975.png" alt="image-20230307152920975"></p>
<p>假如自动驾驶使用监督学习来实现，存在的一个最大问题就是专家示范只是众多可能性中sample出来的，机器碰到不是示范的场景时，机器就不知道做出正确的判断。路口左转是对的，但是如果快要撞到墙了呢，可能车子就撞上去了，因为他没有见过车子还能快要撞到墙。所以supervised learning学出来的行为就是克隆行为了，实用性很差。</p>
<p>另一方面，experts的一些行为，actor是不需要模仿的；actor能力有限，可能无法模仿所有行为，而模仿的行为可能并不能带来好的结果。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307153017119.png" alt="image-20230307153017119"></p>
<h2 id="Inverse-Reinforcement-Learning"><a href="#Inverse-Reinforcement-Learning" class="headerlink" title="Inverse Reinforcement Learning"></a>Inverse Reinforcement Learning</h2><p>原则：老师的行为总是最好的，老师的行为总是能够得到最高的reward，而不是说需要亦步亦趋地模仿。机器自己定reward，即使reward很简单，机器也可能自己衍生出各种复杂的action</p>
<p>從 Expert 的 Demonstration和 Environment，去反推 Reward 應該長什麼樣子。學出一個 Reward Funtion 以後，再直接用一般的 Reinforcement Learning來學你的 Actor。</p>
<p>算法：</p>
<ul>
<li>初始化一个actor</li>
<li>多次迭代<ul>
<li>actor和环境互动，得到一些行为轨迹trajectory τ</li>
<li>定义一个reward函数，这个函数能判断老师的行为比actor的行为好</li>
<li>基于新的reward函数，actor学习如何最大化reward，以接近老师的行为。（这部分是RL）</li>
</ul>
</li>
<li>输出reward函数和学到的actor。</li>
</ul>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307153402114.png" alt="image-20230307153402114"></p>
<p>框架如下图：</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307153425289.png" alt="image-20230307153425289"></p>
<p>逆向强化学习和GAN的思想一样，可以把actor看成generator，把reward函数看成discriminator。generator是尽可能产生真实的图片来获得高分数以骗过discriminator，actor是尽可能生成和专家轨迹一样的轨迹来获得高的奖励分数。discriminator是监督者，努力去分辨真实图片和生成的图片，而reward function则是努力去给专家轨迹打高分而给actor行为打低分。</p>
<p><img src="https://pluto-1300780100.cos.ap-nanjing.myqcloud.com/img/image-20230307153442352.png" alt="image-20230307153442352"></p>

                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/about" rel="external nofollow noreferrer">J Sir</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://jy741.gitee.io/2023/03/07/qiang-hua-xue-xi-reinforcement-learning/">https://jy741.gitee.io/2023/03/07/qiang-hua-xue-xi-reinforcement-learning/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/about" target="_blank">J Sir</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/">
                                    <span class="chip bg-color">机器学习</span>
                                </a>
                            
                                <a href="/tags/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/">
                                    <span class="chip bg-color">深度学习</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2023/03/11/mu-biao-jian-ce-rcnn-xi-lie/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/1.jpg" class="responsive-img" alt="目标检测——RCNN系列">
                        
                        <span class="card-title">目标检测——RCNN系列</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            奶茶鼠的想法爱很简单

R-CNNR-CNN（Region with CNN feature）是目标检测领域的开山之作，原论文名称《Rich feature hierarchies for accurate object detection
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2023-03-11
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-user fa-fw"></i>
                            J Sir
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/">
                        <span class="chip bg-color">深度学习</span>
                    </a>
                    
                    <a href="/tags/%E7%9B%AE%E6%A0%87%E6%A3%80%E6%B5%8B/">
                        <span class="chip bg-color">目标检测</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2023/03/06/ling-yu-gua-ying-domain-adaptation/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/12.jpg" class="responsive-img" alt="领域适应——Domain Adaptation">
                        
                        <span class="card-title">领域适应——Domain Adaptation</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            Domain Shift当训练资料和测试资料存在不同的分布时，在训练资料上训练出来的模型在测试资料上面可能就会坏掉，这样的情况叫做domain shift（域的转变）。比如在黑白的数字上面训练一个模型，直接用到彩色的数字上，得到的正确率会低
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2023-03-06
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-user fa-fw"></i>
                            J Sir
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/">
                        <span class="chip bg-color">机器学习</span>
                    </a>
                    
                    <a href="/tags/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/">
                        <span class="chip bg-color">深度学习</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h1, h2, h3, h4, h5'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h1, h2, h3, h4, h5').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>


<script src="https://cdn.bootcss.com/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
    MathJax.Hub.Config({
        tex2jax: {inlineMath: [['$', '$'], ['\(', '\)']]}
    });
</script>



    <footer class="page-footer bg-color">
    
        <link rel="stylesheet" href="/libs/aplayer/APlayer.min.css">
<style>
    .aplayer .aplayer-lrc p {
        
        display: none;
        
        font-size: 12px;
        font-weight: 700;
        line-height: 16px !important;
    }

    .aplayer .aplayer-lrc p.aplayer-lrc-current {
        
        display: none;
        
        font-size: 15px;
        color: #42b983;
    }

    
    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
        left: -66px !important;
    }

    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body:hover {
        left: 0px !important;
    }

    
</style>
<div class="">
    
    <div class="row">
        <meting-js class="col l8 offset-l2 m10 offset-m1 s12"
                   server="netease"
                   type="playlist"
                   id="503838841"
                   fixed='true'
                   autoplay='false'
                   theme='#42b983'
                   loop='all'
                   order='random'
                   preload='auto'
                   volume='0.7'
                   list-folded='true'
        >
        </meting-js>
    </div>
</div>

<script src="/libs/aplayer/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>

    
    <div class="container row center-align" style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2020-2023</span>
            
            <span id="year">2020</span>
            <a href="/about" target="_blank">J Sir</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
            &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                class="white-color">300.9k</span>&nbsp;字
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">


    <a href="mailto:2065373132@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=2065373132" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 2065373132" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

	
    

    

    

    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"live2d-widget-model-hibiki"},"display":{"position":"right","width":145,"height":315},"mobile":{"show":true,"scale":0.5},"react":{"opacityDefault":0.7,"opacityOnHover":0.8},"log":false});</script></body>

</html>
